package io.zhengsh.juc._3queue;

import java.util.Random;
import java.util.concurrent.PriorityBlockingQueue;

// 优先级队列
public class PriorityBlockingQueueTest {

    public static void main(String[] args) {
        // 默认小顶堆
        PriorityBlockingQueue<Integer> queue = new PriorityBlockingQueue<>();
        Random random = new Random();
        System.out.println("put:");
        for (int i = 0; i < 5; i++) {
            int j = random.nextInt(100);
            System.out.print(j + "\t");
            queue.put(j);
        }
        System.out.println("\ntake:");
        for (int i = 0; i < 5; i++) {
            try {
                Integer j = queue.take();
                System.out.print(j + "\t");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println();
    }
}
